Imports Microsoft.VisualBasic
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System
Imports System.Data
Imports GTSDALTableAdapters
Imports GTSDAL
Imports GTSSystem.BLL.IdGenerator

Namespace GTSSystem.BLL
    <System.ComponentModel.DataObject()> _
Public Class Location

        Private _locationAdaptor As LocationTableAdapter = Nothing

        Protected ReadOnly Property LocationAdaptor() As LocationTableAdapter
            Get
                If _locationAdaptor Is Nothing Then
                    _locationAdaptor = New LocationTableAdapter
                End If
                Return _locationAdaptor
            End Get
        End Property

        'place before lookup statements
        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
        Public Function getLocations() As LocationDataTable
            Try
                Return LocationAdaptor.GetLocations()
            Catch ex As Exception
                Throw
            End Try
        End Function

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
        Public Function getLocationByLocationID(ByVal LocationID As Integer) As LocationDataTable
            Try
                Return LocationAdaptor.GetLocationByLocationID(LocationID)
            Catch ex As Exception
                Throw
            End Try
        End Function
        'place before insert statements
        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Insert, True)> _
        Public Function addLocation(ByVal City As String, ByVal ProvinceState As String, _
                                    ByVal Country As String, ByVal PostalCode As String)
            Try
                Return LocationAdaptor.Insert(GetNextId("Location"), City, ProvinceState, Country, PostalCode)
            Catch ex As Exception
                Throw
            End Try
        End Function
        'place before update statements
        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Update, True)> _
        Public Sub updateLocation(ByVal LocationID As Integer, ByVal City As String, ByVal ProvinceState As String, _
                                        ByVal Country As String, ByVal PostalCode As String)
            Try
                LocationAdaptor.Update(LocationID, City, ProvinceState, Country, PostalCode)
            Catch ex As Exception
                Throw
            End Try
        End Sub
        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
    Public Shared Function GetLocationNameByLocationID(ByVal locationID As Integer) As String
            Dim location As New LocationTableAdapter
            Return location.GetLocationByLocationID(locationID).Rows(0).Item("City")
        End Function
    End Class
End Namespace


